name: "Lint PRs"
on:
  pull_request:
    types:
      - edited
      - opened
      - reopened
      - synchronized
permissions:
  contents: read
jobs:
  # This job checks the PR title using
  # https://github.com/conventional-changelog/commitlint
  # for the conventional commit format at
  # https://www.conventionalcommits.org/en/v1.0.0/
  # See also /.github/commitlint.config.js for more details
  # We only need to check the PR title because it will end up being the
  # (default) commit title when doing squash merges with Github.
  # See
  # https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#merge-message-for-a-squash-merge
  # for more info. We have "Default to PR title for squash merge commits" enabled.
  commit-lint:
    timeout-minutes: 10
    name: "Check PR title"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
        with:
          fetch-depth: 0
      - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
      - run: npm install -g @commitlint/cli @commitlint/config-conventional
      - name: "Check PR title"
        # Inject as env variable to escape properly
        env:
          TITLE: ${{ github.event.pull_request.title }}
        run: |
          commitlint --config .github/commitlint.config.js --edit=<(echo "${TITLE}")
